import {
  checkTitleLenth,
  checkSelect,
  checkTitleLenthNoChinese,
} from '@/portal-common/utils/testedFunc/formValidate/index.js'
export function dataArr() {
  return [
    {
      prop: 'nametext0',
      label: '输入框0',
      type: 'input',
    },
    {
      prop: 'nametext',
      label: '输入框1',
      rules: [
        {
          required: true,
          validator: checkTitleLenth({ max: 50 }),
          trigger: 'change',
        },
      ],
      type: 'input',
    }
  ]
}

export function formTypesConfObj() {
  return {
    input: {
      type: 'input',
      label: '输入框 input',
      rules: [
        {
          required: true,
          validator: checkTitleLenth({ min: 1, max: 50 }),
          trigger: 'change',
        },
      ],
    },
    textarea: {
      type: 'textarea',
      label: '文本域 textarea',
      rules: [
        {
          required: true,
          validator: checkTitleLenth({ min: 1, max: 50 }),
          trigger: 'change',
        },
      ],
    },
    select: {
      type: 'select',
      label: '选择框 select',
      options: [],
      rules: [
        {
          required: true,
          validator: checkSelect(),
          trigger: 'change',
        },
      ],
    },
    radio: {
      type: 'radio',
      label: '单选框 radio',
      options: [],
      rules: [
        {
          required: true,
          validator: checkSelect(),
          trigger: 'change',
        },
      ],
    },
    checkbox: {
      type: 'checkbox',
      label: '多选框 checkbox',
      options: [],
      rules: [
        {
          required: true,
          validator: checkSelect(),
          trigger: 'change',
        },
      ],
    },
    cascader: {
      type: 'cascader',
      label: '级联 cascader',
      options: [],
      rules: [
        {
          required: true,
          validator: checkSelect(),
          trigger: 'change',
        },
      ],
    },
    date: {
      type: 'date',
      label: '日期选择器 date',
      rules: [
        {
          required: true,
          validator: checkSelect(),
          trigger: 'change',
        },
      ],
    },
    daterange: {
      type: 'daterange',
      label: '日期范围选择器 daterange',
      rules: [
        {
          required: true,
          validator: checkSelect(),
          trigger: 'change',
        },
      ],
    },
    dstUpload: {
      type: 'dstUpload',
      label: '上传 dstUpload',
      rules: [
        {
          required: true,
          validator: checkSelect(),
          trigger: 'change',
        },
      ],
    },
    selectDDuser: {
      type: 'selectDDuser',
      label: '钉钉、用户人员selectDDuser',
      rules: [
        {
          required: true,
          validator: checkSelect(),
          trigger: 'change',
        },
      ],
    },
    cutApart: {
      type: 'cutApart',
      label: '做分隔符作用cutApart',
      isNoProp: true,
    },
    button: { type: 'button', label: '按钮button', isNoProp: true },
  }
}
// 校验方法
export const validateList = [
  { name: '文本限制长度', value: 'checkTitleLenth' },
  { name: '下拉框', value: 'checkSelect' },
  { name: '限制数字区间', value: 'rangeNumber' },
  { name: '手机号', value: 'validatePhone' },
  { name: '手机号、电话带分机号', value: 'validatePhoneTel' },
  { name: '邮箱', value: 'validateEmail' },
  { name: '身份证', value: 'validateIdCard' },
]
// 文件类型
export const fileTypes = [
  { name: 'jpg', value: 'jpg' },
  { name: 'jpeg', value: 'jpeg' },
  { name: 'png', value: 'png' },
  { name: 'pdf', value: 'pdf' },
  { name: 'xlsx', value: 'xlsx' },
  { name: 'doc', value: 'doc' },
  { name: 'docx', value: 'docx' },
  { name: 'zip', value: 'zip' },
]

export function commonParamsArr() {
  return [
    {
      label: '类型',
      type: 'select',
      prop: 'type',
      class: 'dst-block',
      props: {
        label: 'label',
        value: 'type',
      },
      options: Object.values(formTypesConfObj()),
      rules: [
        {
          required: true,
          validator: checkSelect(),
          trigger: 'change',
        },
      ],
    },
    {
      label: '字段名',
      type: 'input',
      class: 'dst-block',
      prop: 'label',
      rules: [
        {
          required: true,
          validator: checkTitleLenth({ max: 50 }),
          trigger: 'change',
        },
      ],
    },
    {
      label: '字段',
      type: 'input',
      prop: 'prop',
      class: 'dst-block',
      rules: [
        {
          required: true,
          validator: checkTitleLenthNoChinese({ max: 50 }),
          trigger: 'change',
        },
      ],
    },
    {
      label: '展示方式',
      type: 'radio',
      prop: 'className',
      class: 'dst-block',
      options: [
        { label: '1列式', value: 'dst-block' },
        { label: '2列式', value: '' },
        { label: '3列式', value: 'dst-three-block' },
      ],
    },
    {
      label: '是否必填',
      type: 'radio',
      class: 'dst-block',
      prop: 'required',
      options: [
        { label: '是', value: true },
        { label: '否', value: false },
      ],
    },
  ]
}
